package company.xiecheng;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 携程编程题
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-09-04 19:49
 */
public class X3 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int size = scanner.nextInt();
            int target = scanner.nextInt();
            Order[] orders = new Order[size];
            for (int i = 0; i < size; i++) {
                Order o = new Order();
                o.id = scanner.nextInt();
                o.start = scanner.nextInt();
                o.end = scanner.nextInt();
                orders[i] = o;
            }
            Order t = new Order();
            t.start = target;
            t.end = target;
            int index = Arrays.binarySearch(orders,t);


            if (index < 0){
                if (index == -1 || Math.abs(index) > size||orders[Math.abs(index)-2].end < target)
                    System.out.println("null");
                else
                    System.out.println(orders[Math.abs(index)-2].id);
            }else {
                System.out.println(orders[index].id);
            }

        }
    }
}

class Order implements Comparable<Order>{
    int id;
    int start;
    int end;

    public int compareTo(Order o) {
        return start-o.start;
    }
}
